package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.BomItem;
import com.efast.dmom.mes.bean.BomItemTree;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.BomItemEntity;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.BomItemService;

import io.swagger.annotations.ApiOperation;

/**
 * to achieve the bomItem's new, delete, modify, query methods
 * 
 * @author WJ
 * @data 2020/2/19
 *
 */
@Controller
@RequestMapping("/bomItem")
public class BomItemController {

	@Autowired
	private BomItemService bomItemService;
	
	@RequestMapping(value = "/operateToBasicByBomItem")
	public @ResponseBody ResultBean OperateToBasicByBomItem(@RequestBody BomItem bomItem) {
		
		BomItemEntity entity = bomItem.getInnerData();
		
		 //Determine the new
		if (bomItem.getModificationFlag() == IModificationFlags.NEW) {
			return bomItemService.save(bomItem);
			// Judge update
		} else if (bomItem.getModificationFlag() == IModificationFlags.MODIFIED) {
			return bomItemService.update(bomItem);
			// Judge to delete
		} else if (bomItem.getModificationFlag() == IModificationFlags.DELETED) {
			return bomItemService.delete(bomItem);
		}
		return null;
	}
	
	@ApiOperation(value = "通过BomId获取BomItem")
	@RequestMapping(value = "/getBomItemByBomId")
	public @ResponseBody BomItemTree getBomItemByBomId(@RequestBody BomItem bomItem) {
		return bomItemService.getBomItemByBomId(bomItem);
	}
}
